#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
#include <unordered_set>
#include <algorithm>
using namespace std;
class Solution {
public:
    vector<vector<int>> ret;
    void _sub(vector<int>& num, unordered_set<int>& unset, vector<int>& v)
    {
        if (v.size() == num.size())
        {
            ret.push_back(v);
            return;
        }
        for (int i = 0;i < num.size();++i)
        {
            if (unset.find(num[i]) == unset.end())
            {
                v.push_back(num[i]);
                unset.insert(num[i]);
                _sub(num, unset, v);
                v.pop_back();
                unset.erase(num[i]);
            }
        }
    }
    vector<vector<int> > permute(vector<int>& num)
    {
        sort(num.begin(), num.end());
        unordered_set<int> unset;
        vector<int> v;
        _sub(num, unset, v);
        return ret;
    }
};